package com.tenement.controller;

import com.tenement.common.Axios;
import com.tenement.enums.RespBusiness;
import com.tenement.service.RoleMenuService;
import com.tenement.vo.RoleMenuVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 *  控制层。
 *
 * @author BertXie
 * @since 1.0.1
 */
@RestController
@RequestMapping("/roleMenu")
@RequiredArgsConstructor
@Api(tags = "角色菜单")
public class RoleMenuController {

    private final RoleMenuService roleMenuService;

    @ApiOperation(value = "为角色分配菜单")
    @PutMapping("operator")
    public Axios operator(@RequestBody RoleMenuVo roleMenuVo) {
        return roleMenuService.operator(roleMenuVo) > 0 ? Axios.success(RespBusiness.SUCCESS) : Axios.error(RespBusiness.FAIL);
    }


    @ApiOperation(value = "获取角色菜单")
    @GetMapping("menuIds/{roleId}")
    public Axios menuIds(@PathVariable Long roleId) {
        return Axios.success(roleMenuService.menuIds(roleId));
    }

}
